import { keygen, newHttpClient } from "../test-utils";
import { ExistsCommand } from "./exists";

import { afterAll, describe, expect, test } from "bun:test";
import { SetCommand } from "./set";

const client = newHttpClient();

const { newKey, cleanup } = keygen();
afterAll(cleanup);

describe("when the key does not eist", () => {
  test("it returns 0", async () => {
    const key = newKey();

    const res = await new ExistsCommand([key]).exec(client);
    expect(res).toEqual(0);
  });
});
describe("when the key exists", () => {
  test("it returns 1", async () => {
    const key = newKey();
    await new SetCommand([key, "value"]).exec(client);
    const res = await new ExistsCommand([key]).exec(client);
    expect(res).toEqual(1);
  });
});
describe("with multiple keys", () => {
  test("it returns the number of found keys", async () => {
    const key1 = newKey();
    const key2 = newKey();
    const key3 = newKey();
    await new SetCommand([key1, "value"]).exec(client);
    await new SetCommand([key2, "value"]).exec(client);
    const res = await new ExistsCommand([key1, key2, key3]).exec(client);
    expect(res).toEqual(2);
  });
});
